package com.zh.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class Advice {
    @Pointcut("execution(* *com.zh.service.*.* (..))")
    private void pc(){}
    @Around("pc()")
    public Object advice(ProceedingJoinPoint joinPoint) throws Throwable {
        long begin = System.currentTimeMillis();
        System.out.println("advice-------before");
        Object result = joinPoint.proceed();
        Object[] args = joinPoint.getArgs();
        for (int i = 0; i < args.length; i++) {
            System.out.println(args[i]);
        }
        System.out.println("advice-------after");
        long end = System.currentTimeMillis();
        System.out.println(end-begin);
        return result;
    }
}
